realtek: mdio-serdes: improve debugfs creation
authorJonas Jelonek <[email protected]>
Tue, 16 Dec 2025 10:20:13 +0000 (10:20 +0000)
committerRobert Marko <[email protected]>
Tue, 16 Dec 2025 12:11:34 +0000 (13:11 +0100)
Commit 3c073b5cb2 cleaned up the debugfs creation in
mdio-realtek-otto-serdes driver to not explicitly check if the root
directory already exists. This is fine because kernel handles the case
properly so there's no need to check anymore.

However, this pollutes the boot log with:
[..] debugfs: 'realtek_otto_serdes' already exists in '/'
[..] debugfs: 'realtek_otto_serdes' already exists in '/'
[..] debugfs: 'realtek_otto_serdes' already exists in '/'
[..] debugfs: 'realtek_otto_serdes' already exists in '/'
[..] debugfs: 'realtek_otto_serdes' already exists in '/'
[..] debugfs: 'realtek_otto_serdes' already exists in '/'
[..] debugfs: 'realtek_otto_serdes' already exists in '/'
[..] debugfs: 'realtek_otto_serdes' already exists in '/'
[..] debugfs: 'realtek_otto_serdes' already exists in '/'
[..] debugfs: 'realtek_otto_serdes' already exists in '/'
[..] debugfs: 'realtek_otto_serdes' already exists in '/'

Now, the root directory creation is attempted multiple times, causing
the kernel to print an error message because the directory already
exists.

Fix this by moving the SerDes loop into rtsds_debug_init and only try
to create the root debugfs directory once.

Signed-off-by: Jonas Jelonek <[email protected]>
Link: https://github.com/openwrt/openwrt/pull/21179
Signed-off-by: Robert Marko <[email protected]>
target/linux/realtek/files-6.12/drivers/net/mdio/mdio-realtek-otto-serdes.c

index 5c8741383f80ea8aabf158605b30b65a04ea151a..097fcc41b4f99f5952abeb8ce5c4f61eab813b54 100644 (file)
@@ -142,27 +142,30 @@ static int rtsds_dbg_registers_show(struct seq_file *seqf, void *unused)
 }
 DEFINE_SHOW_ATTRIBUTE(rtsds_dbg_registers);
 
-static int rtsds_debug_init(struct rtsds_ctrl *ctrl, u32 sds)
+static int rtsds_debug_init(struct rtsds_ctrl *ctrl)
 {
        struct rtsds_debug_info *dbg_info;
        struct dentry *dir, *root;
        char dirname[32];
 
-       dbg_info = devm_kzalloc(ctrl->dev, sizeof(*dbg_info), GFP_KERNEL);
-       if (!dbg_info)
-               return -ENOMEM;
-
-       dbg_info->ctrl = ctrl;
-       dbg_info->sds = sds;
-
        root = debugfs_create_dir(RTSDS_DBG_ROOT_DIR, NULL);
        if (IS_ERR(root))
                return PTR_ERR(root);
 
-       snprintf(dirname, sizeof(dirname), "serdes.%d", sds);
-       dir = debugfs_create_dir(dirname, root);
+       for (int sds = 0; sds < ctrl->cfg->sds_cnt; sds++) {
+               dbg_info = devm_kzalloc(ctrl->dev, sizeof(*dbg_info), GFP_KERNEL);
+               if (!dbg_info)
+                       return -ENOMEM;
 
-       debugfs_create_file("registers", 0600, dir, dbg_info, &rtsds_dbg_registers_fops);
+               dbg_info->ctrl = ctrl;
+               dbg_info->sds = sds;
+
+               snprintf(dirname, sizeof(dirname), "serdes.%d", sds);
+               dir = debugfs_create_dir(dirname, root);
+
+               debugfs_create_file("registers", 0600, dir, dbg_info,
+                                   &rtsds_dbg_registers_fops);
+       }
 
        return 0;
 }
@@ -461,8 +464,7 @@ static int rtsds_probe(struct platform_device *pdev)
                return ret;
 
 #ifdef CONFIG_DEBUG_FS
-       for (int sds = 0; sds < ctrl->cfg->sds_cnt; sds++)
-               rtsds_debug_init(ctrl, sds);
+       rtsds_debug_init(ctrl);
 #endif
 
        dev_info(dev, "Realtek SerDes mdio bus initialized, %d SerDes, %d pages, %d registers\n",